package com.zhongwang.mms.module.basic.service;


import com.zhongwang.mms.module.basic.dao.OrgMapper;
import com.zhongwang.mms.module.basic.dao.VerifyMapper;
import com.zhongwang.mms.module.basic.model.Verify;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static com.zhongwang.mms.util.BeanUtil.copy;


/**
 * @Description:
 * @Author: China.sgl
 * @Date: 2019/12/6 08:42
 */
@Service
@SuppressWarnings("all")
public class VerifyService {

    @Autowired
    private VerifyMapper verifyMapper;
    @Autowired
    private OrgMapper orgMapper;


    /**
     * 按条件查询
     */
    public List<Verify> findByCondition(Verify verify) {
        return verifyMapper.findByCondition(verify);
    }

    /**
     * 保存
     */
    @Transactional(rollbackFor = Exception.class)
    public Verify saveVerify(Verify verify) {
        if (verify.getId() == null) {
            verify.setId(0);
        }
        Verify byIdEntity = verifyMapper.getVerifyById(verify.getId());
        if (byIdEntity == null) {
            return verifyMapper.insert(verify);
        }
        verifyMapper.update(verify);
        return verifyMapper.getVerifyById(verify.getId());
    }

    /**
     * 修改
     */
    public Verify updateVerify(Verify verify) {
        Verify target = verifyMapper.getVerifyById(verify.getId());
        copy(verify, target);
        verifyMapper.update(target);
        return verifyMapper.getVerifyById(target.getId());
    }


}
